import { createCommonPage, COLUMN_WIDTH } from '@/utils/service.js'
import { dateFormat } from '@/utils/date'

/* {
    "id": 1,
    "title": "test",
    "url": "www.test.cn",
    "createTime": "2024-08-09 15:56:29",
    "contextType": "IMAGE",
    "state": {
        "key": "ADMIN_AUDITING",
        "value": "待管理端审核"
    },
    "createBy": "default"
} */
export const createColumns = (vm) => {
  const audit = vm.hasPermission('article/manager/needAudit/audit')
  return [
    {
      title: '',
      width: 34,
      align: 'center',
      type: 'selection',
    },
    {
      title: '序号',
      key: 'id',
      align: 'center',
      width: 80,
      render(h, params) {
        return <div>{(vm.formData.pageNo - 1) * vm.formData.pageSize + params.index + 1}</div>
      },
    },
    {
      title: '稿件标题',
      align: 'center',
      width: COLUMN_WIDTH + 300,
      render(h, params) {
        return <article-title info={params.row}></article-title>
      },
    },
    { title: '上传用户', key: 'createBy', align: 'center' },
    {
      title: '上传时间',
      align: 'center',
      sortable: 'custom',
      sortType: 'desc',
      render(h, params) {
        return <div>{dateFormat(params.row.createTime || '', 'YYYY.MM.DD HH:mm:ss')}</div>
      },
    },
    {
      title: '操作',
      align: 'center',
      render(h, params) {
        /* ADMIN_AUDITING */
        if (audit) {
          return (
            <icon-button
              icon="audit_active"
              title="审核"
              activated={false}
              nativeOnClick={() => {
                vm.handleAudit(params.row)
              }}
            ></icon-button>
          )
        } else {
          return h('span', vm.noBtnText)
        }
      },
    },
  ]
}
